package org.shijiagen.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.shijiagen.param.AddressRemoveParam;
import org.shijiagen.pojo.Address;
import org.shijiagen.user.mapper.AddressMapper;
import org.shijiagen.user.service.AddressService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@RequiredArgsConstructor
public class AddressServiceImpl implements AddressService {

    private final AddressMapper addressMapper;

    @Override
    public List<Address> list(Integer userId) {
        return addressMapper.selectList(new QueryWrapper<Address>().eq("user_id",userId));
    }

    @Override
    public List<Address> save(Address address) {
        int rows = addressMapper.insert(address);
        if(rows == 0){
            return null;
        }
        return list(address.getUserId());
    }

    @Override
    public Boolean remove(AddressRemoveParam addressRemoveParam) {
        int rows = addressMapper.deleteById(addressRemoveParam.getId());
        return rows != 0;
    }
}
